const router = require('koa-router')()
const util = require('../utils/util')
const Ocr = require('../models/ocr')
// utils.ocrText()

router.prefix('/ocr')

// /api/ocr/text
router.post('/text', async (ctx, next) => {
	const file = ctx.request.body.file
	let authorization = ctx.request.headers.authorization
	let { data } = util.decoded(authorization)
	// data.userId
	const result = await util.ocrText(file)

	const res = await Ocr.create({
		userId: data.userId,
		text: { ...result }
	})

	ctx.body = {
		code: 0,
		msg: 'success',
		data: { result, res }
	}
})

module.exports = router
